package com.owen.controller;

import com.owen.pojo.User;

import javax.servlet.http.HttpSession;
import java.util.Optional;

/**
 * 用于获取登录用户基本信息
 */
public class BaseController {



    /**
     * 获取登录用户信息
     * @param session
     * @return
     */
    public User getLoginUser(HttpSession session) {
        User user = (User) session.getAttribute("login");
        return user;
    }

    /**
     * 获取登录用户id
     * @param session
     * @return
     */
    public Long getLoginUserId(HttpSession session) {
        User user = (User) session.getAttribute("login");
        return Optional.ofNullable(user).map(u -> u.getId()).orElse(0L);
    }


}
